#ifndef ATOM_DEMO_H
#define ATOM_DEMO_H

#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <vector>
#include <map>
#include <chrono>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>

using namespace std;
using namespace std::chrono;
using namespace cv;


/*DEMO_STATUS_*/
#define DEMO_STATUS_UNINITIALIZED 1
#define DEMO_STATUS_DEVICE_INITIALIZED 2 
#define DEMO_STATUS_INITIALIZED 3 
#define DEMO_STATUS_PRELAUNCHING 4 
#define DEMO_STATUS_RUN 5
#define DEMO_STATUS_STOP 6  
#define DEMO_STATUS_EXCEPTION 7
#define DEMO_STATUS_IDEL 8
#define DEMO_STATUS_EXIT 9
//...
/*DEMO_STATUS_*/


/*EVENT_NUM_REQUEST_*/
#define EVENT_NCOUNT 13
#define DEFAULT_REQUEST_INTERVAL 1000 // in milliseconds
#define EVENT_NUM_TERMINATE_THREAD_1 1
#define EVENT_NUM_TERMINATE_THREAD_2 2
#define EVENT_NUM_REQUEST_TERMINATE 3
#define EVENT_NUM_REQUEST_4 4
#define EVENT_NUM_REQUEST_5 5
#define EVENT_NUM_REQUEST_6 6
#define EVENT_NUM_REQUEST_7 7
#define EVENT_NUM_REQUEST_8 8 
#define EVENT_NUM_REQUEST_9 9
#define EVENT_NUM_REQUEST_10 10
#define EVENT_NUM_REQUEST_11 11
#define EVENT_NUM_REQUEST_12 12
#define EVENT_NUM_REQUEST_13 13
 
//...
/*EVENT_NUM_REQUEST_*/


#define TEST_MODE_FILE_RECORD 1
#define THREAD_CREATION_MAX_TRIALS 5

class AtomDemo
{


public:

     AtomDemo();
    ~AtomDemo();

    bool Init_();
    bool MainTask();
    bool ExitMainTask(BYTE bTerminate);
    void EndMultiThreads();
    
    bool PrepareAndCreateMultiThread();
    void EventListLoopHandle(BYTE& commandType);
     
    int KeyTest(void);
    void ConvertKeyToSignal(char userKey);

    static void* Thread_1(void* lpPara);
    static void* Thread_2(void* lpPara);

protected:

    cv::Mat littlergb,bigrgb;//大小视频的rgb  
    cv::Mat littleframe,bigframe;//大小视频的yuv  

#ifdef   TEST_MODE_FILE_RECORD 
    ofstream m_OF_rec;
    ofstream m_OF_path_rec;
    bool PrepareRecordFile();
    void SaveDateRecord(ofstream& m_OF_rec);
    int m_curFileNo;
#endif

    map<ofstream*, std::string> stream_file_table;  

    BYTE bTimed[EVENT_NCOUNT];
    DWORD waitTime[EVENT_NCOUNT] = {10,10,10,10,10,10,10,10,10,10,10,10,10};
    
    ATOM_Event_List Demo_Event_List;
    
    pthread_t m_THREAD_1;
    pthread_t m_THREAD_2;

    int m_nState;

    cv::VideoCapture capture1;
    cv::VideoCapture capture2;
    cv::Mat frame1,frame2;



};

#endif
